package com.weidey.blog.controller;

import java.util.List;
import com.weidey.blog.domain.Group;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.weidey.common.annotation.Log;
import com.weidey.common.core.controller.BaseController;
import com.weidey.common.core.domain.AjaxResult;
import com.weidey.common.enums.BusinessType;
import com.weidey.blog.service.IGroupService;
import com.weidey.common.utils.poi.ExcelUtil;
import com.weidey.common.core.page.TableDataInfo;

/**
 * 博客分组表Controller
 * 
 * @author weidey
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/blog/group")
public class GroupController extends BaseController
{
    @Autowired
    private IGroupService blogGroupService;

    /**
     * 查询博客分组表列表
     */
    @PreAuthorize("@ss.hasPermi('blog:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(Group group)
    {
        startPage();
        List<Group> list = blogGroupService.selectBlogGroupList(group);
        return getDataTable(list);
    }

    /**
     * 导出博客分组表列表
     */
    @PreAuthorize("@ss.hasPermi('blog:group:export')")
    @Log(title = "博客分组表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Group group)
    {
        List<Group> list = blogGroupService.selectBlogGroupList(group);
        ExcelUtil<Group> util = new ExcelUtil<Group>(Group.class);
        util.exportExcel(response, list, "博客分组表数据");
    }

    /**
     * 获取博客分组表详细信息
     */
    @PreAuthorize("@ss.hasPermi('blog:group:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(blogGroupService.selectBlogGroupById(id));
    }

    /**
     * 新增博客分组表
     */
    @PreAuthorize("@ss.hasPermi('blog:group:add')")
    @Log(title = "博客分组表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Group group)
    {
        return toAjax(blogGroupService.insertBlogGroup(group));
    }

    /**
     * 修改博客分组表
     */
    @PreAuthorize("@ss.hasPermi('blog:group:edit')")
    @Log(title = "博客分组表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Group group)
    {
        return toAjax(blogGroupService.updateBlogGroup(group));
    }

    /**
     * 删除博客分组表
     */
    @PreAuthorize("@ss.hasPermi('blog:group:remove')")
    @Log(title = "博客分组表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids)
    {
        return toAjax(blogGroupService.deleteBlogGroupByIds(ids));
    }


    /**
     * 获取所有文章分组
     */
    @PreAuthorize("@ss.hasPermi('blog:group:list')")
    @GetMapping("/list/all")
    public AjaxResult listAll(){
        List<Group> list = blogGroupService.selecttAllBlogGroupList();
        return success(list);
    }

}
